﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sys.WebRes.Data
{
    public partial class ResStatusType
    {
        public static Dictionary<int, ResStatusType> Map = new Dictionary<int, ResStatusType>();

        public static ResStatusType NotReviewed = new ResStatusType(1, "未审核", "NotReviewed", "未审核", 1);
        public static ResStatusType Reviewed    = new ResStatusType(2, "审核",   "Reviewed",    "审核",  2);
        public static ResStatusType Publish     = new ResStatusType(3, "发布",   "Publish",     "发布",  3);
        public static ResStatusType Close       = new ResStatusType(4, "关闭",   "Close",       "关闭",  4);
        public static ResStatusType Recycle     = new ResStatusType(5, "回收站", "Recycle",     "回收站", 5);

        public static void Initialize(ResourceSysEntities db){
            var list = db.ResStatusTypeTBL.ToList();
            if (list.Count > 0)
            {
                list.ForEach(p =>
                {
                    Map[p.ID].Name = p.Name;
                    Map[p.ID].Abbr = p.Abbr;
                    Map[p.ID].Explain = p.Explain;
                    Map[p.ID].OrderNo = p.OrderNo;
                });
            }
            else
            {
                Array.ForEach(Map.Values.ToArray(), p =>
                {
                    db.AddToResStatusTypeTBL(p);
                });
            }
        }

        private ResStatusType(int id, string name, string abbr, string explain, int orderNo)
        {
            this.ID = id;
            this.Name = name;
            this.Abbr = abbr;
            this.Explain = explain;
            this.OrderNo = orderNo;

            Map.Add(id, this);
        }

        public ResStatusType() { }
    }
}
